﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kenly.ChineseSegment.Core
{
    /// <summary>
    /// 分词及其出现的次数。
    /// </summary>
    public class SegmentCountPair:IComparable<SegmentCountPair>
    {
        private string _segment;
        private int _count;
        private int _defaultIndex;

        /// <summary>
        /// 分词。
        /// </summary>
        public string Segment
        {
            get
            {
                return _segment;
            }
            set
            {
                _segment = value;
            }
        }

        /// <summary>
        /// 出现的次数。
        /// </summary>
        public int Count
        {
            get
            {
                return _count;
            }
            set
            {
                _count = value;
            }
        }

        /// <summary>
        /// 当前对象在链表中的默认位置。
        /// </summary>
        public int DefaultIndex
        {
            get
            {
                return _defaultIndex;
            }
            set
            {
                _defaultIndex = value;
            }
        }

        #region IComparable<SegmentCountPair> 成员

        public int CompareTo(SegmentCountPair other)
        {
            //若次数相同，按默认顺序排序。
            if (this.Count == other.Count)
            {
                return this.DefaultIndex - other.DefaultIndex;
            }
            return this.Count - other.Count;
        }

        #endregion
    }
}
